package cn.shuangliang.contract.service;

import cn.shuangliang.contract.vo.Constant;
import cn.shuangliang.contract.dao.ProductMapper;
import cn.shuangliang.contract.model.Product;
import cn.shuangliang.contract.vo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
@Service
public class ProductService {
    @Autowired
    private ProductMapper  mapper;
    public int add(Product p){

            return mapper.insertSelective(p);

    }
    public int update(Product p){

            return mapper.updateByPrimaryKey(p);

    }
    public Product get(Long id){

            return mapper.selectByPrimaryKey(id);

    }
    public Page<Product> search(  int pageNo,    String pname,  String type){

            List<Product> search = mapper.search(pageNo, Constant.pageSize , pname, type);
            int total = mapper.searchTotal( pname, type);
            return new Page<Product>(search,pageNo,total, Constant.pageSize );

    }

    public Page<Product> search(  int pageNo,int pageSize,    String pname,  String type){

            List<Product> search = mapper.search(pageNo, pageSize , pname, type);
            int total = mapper.searchTotal( pname, type);
            return new Page<Product>(search,pageNo,total, Constant.pageSize );

    }

    public int del(Long id) {
            return  mapper.deleteByPrimaryKey(id);

    }
}
